package com.starsea.book.ui.newpage.adapter

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter

/**
 * Desc :
 */
class MyPagerAdapter(fm: FragmentManager?, mFragments: List<Fragment>, mTitles: List<String>) :
  FragmentPagerAdapter(
    fm!!, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
  ) {
  private var mFragments: List<Fragment> = ArrayList()
  private var mTitles: List<String> = ArrayList()

  init {
    this.mFragments = mFragments
    this.mTitles = mTitles
  }

  override fun getCount(): Int {
    return if (mFragments.isEmpty()) 0 else mFragments.size
  }

  override fun getPageTitle(position: Int): CharSequence {
    return if (mTitles.isEmpty()) "" else mTitles[position]
  }

  override fun getItem(position: Int): Fragment {
    return mFragments[position]
  }
}
